package com.phkj.qdh.ui.adapter

import android.content.Context
import android.os.Parcelable
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.phkj.qdh.R
import kotlinx.parcelize.Parcelize

class FileTitleAdapter : BaseQuickAdapter<UploadFileBean, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: UploadFileBean?) {
        val tv = holder.getView<TextView>(R.id.tv_file)
        val iv = holder.getView<ImageView>(R.id.iv)
        if (item!!.fileName.contains(".doc")) {
            iv.setImageResource(R.mipmap.word)
        } else if (item.fileName.contains(".xl")) {
            iv.setImageResource(R.mipmap.excel)
        } else if (item.fileName.contains(".ppt")) {
            iv.setImageResource(R.mipmap.ppt)
        } else {
            iv.setImageResource(R.mipmap.ic_add_file)
        }
        if (item.fileName.length > 12) {
            val sb = StringBuilder(item.fileName)
            tv.text = sb.substring(sb.length - 12, sb.length).toString()
        } else {
            tv.text = item.fileName
        }
    }

    override fun onCreateViewHolder(
        context: Context, parent: ViewGroup, viewType: Int
    ): QuickViewHolder {
        return QuickViewHolder(R.layout.item_add_file_head, parent)
    }
}
@Parcelize
data class UploadFileBean(
    val fileName:String,
    val fileUrl:String
):Parcelable